<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
// define the colors array
$colors = array('black', 'blue', 'brown', 'green', 'grey',
    'gold', 'navy', 'orange', 'pink', 'silver',
    'violet', 'yellow', 'red');

date_default_timezone_set('Europe/London');
$user = "developer";
$password = "RMBPdevTEAMbigQ9";
$database = "storedb";
$host = "192.168.100.125";

// check the parameter
if (isset($_GET['part']) and $_GET['part'] != '') {
    $month = date("m");
    $day = date("d");
    $year = date("Y");

    $date_to = $year . "-" . $month . "-" . $day;
    $date_from = $year . "-" . $month . "-01";

    $part = $_GET['part'];

    $query = "SELECT manufacturer, count(*) as products FROM product p, contentobject co WHERE p.productid = co.contentobjectid
    AND shopid = 9886 AND co.isvisible = 1 AND co.visibleinnavigation = 1 AND upper(manufacturer) LIKE upper('%$part%') group by manufacturer";


#SELECT ls.value as category, count(*) as products FROM product p, categoryproductmap c, localizedstringattribute l WHERE
#p.productid = c.productid AND c.categoryid = l.objectid AND l.languageid = 2 AND upper(value) LIKE upper('%tong%')
#SELECT * FROM localizedstringattribute l WHERE objectid = 10098 AND languageid = 2 LIMIT 0,1000
#SELECT categoryproductmap
#
#localizedstringattribute



    mysql_connect($host, $user, $password);
    @mysql_select_db($database) or die("Unable to select database");
    $result = mysql_query($query);
    mysql_close();

    $results = array();
    while ($row = mysql_fetch_array($result)) {
        $results[] = $row['manufacturer'] . " -  " . $row['products'];
    }


    // initialize the results array
#	$results = array();
    // search colors
#	foreach($colors as $color)
#	{
#		// if it starts with 'part' add to results
#		if( strpos($color, $_GET['part']) === 0 ){
#			$results[] = $color;
#		}
#	}
#
    // return the array as json with PHP 5.2
    echo json_encode($results);

    // or return using Zend_Json class
    //require_once('Zend/Json/Encoder.php');
    //echo Zend_Json_Encoder::encode($results);
}
